{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>分润导入</h5>
        </div>
        <div class="ibox-content" id="branch">
            <div class="example-wrap">
                <div class="example">
                    <div class="layui-col-sx12" id="ti">
                        <form action="" class="layui-form layui-form-pane">
                            <div class="layui-form-item" style="height: 65px;">
                                <div class="layui-inline">
                                    <label class="layui-form-label">品牌</label>
                                    <div class="layui-input-inline">
                                        <select name="brand">
                                            <option value="">----请选择----</option>
                                            <option value="lakala">拉卡拉</option>
                                            <option value="youshua">友刷</option>
                                            <option value="leshua">乐刷</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">请上传文件</label>
                                    <div class="layui-input-inline">
                                        <div class="layui-upload">
                                            <a type="button" class="layui-btn layui-btn-normal" id="test8">选择文件</a>
                                            <input type="hidden" name="filename" id="filename">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <div class="layui-input-inline">
                                        <div class="layui-btn-group">
                                            <a type="button" class="layui-btn" lay-submit lay-filter="loads">读取数据</a>
                                            <a type="button" class="layui-btn layui-btn-danger" onclick="clearData()">清除数据</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>

                    <table class="layui-table">
                        <colgroup>
                            <col>
                            <col>
                            <col>
                            <col>
                            <col>
                            <col>
                            <col>
                            <col>
                            <col>
                        </colgroup>
                        <thead>
                        <tr>
                            <th>商户号</th>
                            <th>商户名称</th>
                            <th>终端号</th>
                            <th>卡类型</th>
                            <th>交易类型</th>
                            <th>交易日期</th>
                            <th>交易金额</th>
                            <th>手续费</th>
                            <th>支付时间</th>
                        </tr>
                        </thead>
                        <tbody id="tbody">
                        {notempty name="data"}
                        {foreach name="data" id="value"}
                        <tr>
                            <td>{$value['shop_num']}</td>
                            <td>{$value['shop_name']}</td>
                            <td>{$value['zhong_duan']}</td>
                            <td>{$value['card_type']}</td>
                            <td>{$value['type']}</td>
                            <td>{:date('Y年m月d日 H时i分s秒',$value['jiaoyi_date'])}</td>
                            <td>{$value['jiaoyi_money']}</td>
                            <td>{$value['jiaoyi_shouxu']}</td>
                            <td>{:date('Y年m月d日 H时i分s秒',$value['pay_date'])}</td>
                        </tr>
                        {/foreach}
                        {/notempty}
                        </tbody>
                    </table>

                </div>
            </div>
            <!-- End Example Pagination -->
        </div>
    </div>
</div>
<!-- End Panel Other -->

<!-- 加载动画 -->
<div class="spiner-example">
    <div class="sk-spinner sk-spinner-three-bounce">
        <div class="sk-bounce1"></div>
        <div class="sk-bounce2"></div>
        <div class="sk-bounce3"></div>
    </div>
</div>
{include file="public/footer" /}
<script type="text/javascript">
    var table = layui.table, form = layui.form, upload = layui.upload;
    $(".spiner-example").css('display', 'none'); //数据加载完关闭动画

    /**
     * 清除缓存数据
     */
    function clearData() {
        $.post("{:url('clears')}", function (response) {
            if (response.code === 200)
                $('#tbody').html('');
        })
    }

    form.on('submit(loads)', function (response) {
        var param = response.field;
        if (!param.brand) {
            layer.msg('请选择品牌', {icon: 2});
            return false;
        }
        if (!param.filename) {
            layer.msg('请选择文件', {icon: 2});
            return false;
        }
        var loads = layer.load(2);
        $.post("{:url('import')}", param, function (response) {
            console.log(response);
            layer.close(loads);
            if (response.code === 200) {
                $('#tbody').html(response.data);
            } else {
                layer.msg(response.msg, {icon: 2});
            }
        });
        return false;
    });

    //选完文件后不自动上传
    upload.render({
        elem: '#test8',
        url: "{:url('Upload/uploadExcel')}",
        method: 'post',
        auto: true,
        // multiple: true,
        accept: 'file',
        exts: 'xls|xlsx',
        bindAction: '#test8_btn',
        before: function () {
            layer.load(2);
        },
        done: function (response) {
            layer.closeAll();
            if (response.code === 200) {
                $('#filename').val(response.data);
            } else {
                layer.msg(response.msg, {icon: 2});
            }
        },
        error: function (error) {
            setTimeout(function () {
                layer.closeAll();
            }, 2000);
        }
    });
</script>
</body>
</html>